<!--往来单位信息 -->
<template>
  <div class="basic_info">
    <div class="info_operation_btn">
      <div class="btn_left">
        <el-button
          type="primary"
          :disabled="!buttonsPermissions.XinZeng"
          :class="!buttonsPermissions.XinZeng ? 'disabled_button' : ''"
          @click="onShowAdd"
          >新增(N)</el-button
        >
        <!-- <el-button :disabled="!buttonsPermissions.DaoRu" @click="importExcel">导入</el-button> -->
        <el-select v-model="importValue">
          <el-option
            label="导入"
            value="导入"
            :disabled="!buttonsPermissions.DaoRu"
            :style="!buttonsPermissions.DaoRu ? 'pointer-events: none;font-size: 12px' : 'font-size: 12px'"
            @click.native="importExcel"
          ></el-option>
          <el-option
            label="导出"
            value="导出"
            :disabled="!buttonsPermissions.DaoChu"
            :style="!buttonsPermissions.DaoChu ? 'pointer-events: none;font-size: 12px' : 'font-size: 12px'"
            @click.native="exportExcel"
          ></el-option>
        </el-select>
        <el-select v-model="enableValue" :visible-change="false">
          <el-option
            style="font-size: 12px"
            @click.native="onBatchChangeStatus(enableValue)"
            v-for="item in enableOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-button
          :disabled="!buttonsPermissions.ShanChu"
          :class="!buttonsPermissions.ShanChu ? 'disabled_button' : ''"
          @click="onBatchDelete"
          >批量删除</el-button
        >
        <el-checkbox v-model="queryData.status">显示禁用{{baseText}}</el-checkbox>
      </div>
      <div class="btn_right">
        <el-input
          @change="onQuery"
          v-model="queryData.queryParam"
          placeholder="请输入单位名称\联系人\电话\地址"
        ></el-input>
        <el-button type="primary" @click="onQuery">搜索</el-button>
        <el-button @click="onRefresh">刷新</el-button>
        <i @click="onShowColumn" class="set_up el-icon-s-tools"></i>
      </div>
    </div>
    <div class="info_content_div">
      <div class="div_tree" :class="editTreeDataSta == false ? 'new_div_tree_width' : ''">
        <div class="tree_div1">
          <p>{{baseText}}类别</p>
          <p v-if="editTreeDataSta" @click="editTreeDataSta = false">编辑</p>
          <el-button v-else type="primary" @click="editTreeDataSta = true">完成编辑</el-button>
        </div>
        <div class="tree_input">
          <p>
            <input type="text" placeholder="查找" v-model="filterText" />
            <span>
              <i class="el-icon-search"></i>
            </span>
          </p>
        </div>
        <div class="tree_structure">
          <el-tree
            ref="tree"
            :data="treeData"
            node-key="label"
            :props="defaultProps"
            :draggable="!editTreeDataSta"
            highlight-current
            default-expand-all
            :expand-on-click-node="false"
            @node-click="handleNodeClick"
            :filter-node-method="filterNode"
          >
            <!-- @node-drop="handleDrop"
            :allow-drop="allowDrop"-->

            <span v-if="editTreeDataSta == false" class="tree_node" slot-scope="{ node, data }">
              <span class="tree_label">{{ node.label }}</span>
              <span v-if="nowLabel == data.id" class="show_nodex">
                <i class="el-icon-circle-plus-outline" @click.stop="onAddTree(data)"></i>
                <i
                  v-if="!['0', '1', '2'].includes(data.id)"
                  class="el-icon-edit-outline"
                  @click.stop="onEditTree(node, data)"
                ></i>
                <i
                  v-if="!['0', '1', '2'].includes(data.id)"
                  class="el-icon-delete"
                  @click.stop="onDeleteTree(data)"
                ></i>
              </span>
            </span>
            <span v-else class="tree_node" slot-scope="{ node }">
              <span class="tree_label">{{ node.label }}</span>
            </span>
          </el-tree>
        </div>
      </div>
      <div class="div_table" :class="editTreeDataSta == false ? 'new_div_table_width' : ''">
        <div class="table_content">
          <el-table
            ref="tableRef"
            :data="tableData.records"
            height="100%"
            border
            tooltip-effect="dark"
            highlight-current-row
            :header-cell-style="{ background: '#EDEDED', color: '#666666', textAlign: 'center' }"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" :resizable="false"></el-table-column>
            <el-table-column
              label="操作"
              :width="180"
              :resizable="false"
              v-if="buttonsPermissions.ShanChu && buttonsPermissions.XiuGai"
            >
              <template slot-scope="scope">
                <!-- 客户 -->
                <template v-if="scope.row.xghCompanyNatureId === '2'">
                  <img
                    src="@/assets/img/xsckd.png"
                    title="销售出库单"
                    class="option-icon"
                    @click="handleImgClick(scope.row, 'xsckd')"
                  />
                  <img
                    src="@/assets/img/skd.png"
                    title="收款单"
                    class="option-icon"
                    @click="handleImgClick(scope.row, 'skd')"
                    v-if="!isBaseVersion"
                  />
                  <img
                    src="@/assets/img/wldzd.png"
                    title="往来对账[按单据]"
                    class="option-icon"
                    @click="handleImgClick(scope.row, 'wldzd')"
                    v-if="!isBaseVersion"
                  />
                </template>
                <!-- 供应商 -->
                <template v-if="scope.row.xghCompanyNatureId === '1' && !isBaseVersion">
                  <img
                    src="@/assets/img/cgrkd.png"
                    title="采购入库单"
                    class="option-icon"
                    @click="handleImgClick(scope.row, 'cgrkd')"
                  />
                  <img
                    src="@/assets/img/fkd.png"
                    title="付款单"
                    class="option-icon"
                    @click="handleImgClick(scope.row, 'fkd')"
                  />
                  <img
                    src="@/assets/img/wldzd.png"
                    title="往来对账[按单据]"
                    class="option-icon"
                    @click="handleImgClick(scope.row, 'wldzd')"
                  />
                </template>
                <i v-if="buttonsPermissions.XiuGai" @click="onEditRow(scope.row)" class="el-icon-edit-outline"></i>
                <i v-if="buttonsPermissions.ShanChu" @click="onDeleteRow(scope.row)" class="el-icon-delete"></i>
              </template>
            </el-table-column>
            <template v-for="(item, i) in columnData">
              <el-table-column
                :key="i"
                :show-overflow-tooltip="true"
                :prop="item.props"
                :label="item.zidingyiName ? item.zidingyiName : item.morenName"
                min-width="150px"
                v-if="item.zidingyiState"
                :resizable="false"
                :width="item.cellWidth"
              >
                <template slot-scope="scope">
                  <div v-if="item.morenName == '地址'">
                    {{ scope.row.provinceName }}{{ scope.row.cityName }}{{ scope.row.countyName
                    }}{{ scope.row.address }}
                  </div>
                  <div v-else>{{ scope.row[item.props] }}</div>
                </template>
              </el-table-column>
            </template>
            <el-table-column label="状态" :resizable="false" fixed="right">
              <template slot-scope="scope">
                <el-switch
                  @change="onChangeStatus(scope.row)"
                  v-model="scope.row.status"
                  active-color="#1A93FA"
                  inactive-color="#D3D2D2"
                ></el-switch>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="total_record">
          <p>合计</p>
          <p>共{{ tableData.total }}条记录</p>
        </div>
        <div class="table_pagination">
          <div class="pagination_div">
            <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[20, 50, 100, 200]"
              :page-size="pagesize"
              layout="jumper, prev, pager,next, sizes"
              :total="tableData.total"
            ></el-pagination>
          </div>
        </div>
      </div>
    </div>
    <!-- 列配置弹框 -->
    <CConfiguration
      ref="setColumnRef"
      :columnDataArr="columnData"
      :defaultColumnDataArr="defaultColumnData"
      orderType="往来单位信息"
      @onSaveColumn="onSaveColumn"
    ></CConfiguration>
    <!-- 新增树形结构数据弹框 -->
    <el-dialog
      :title="this.newTreeData.module.name == 'deptName' ? '部门' : '类别信息'"
      :visible.sync="showNewTree"
      width="480px"
    >
      <NewCategory
        :newTreeData="newTreeData"
        @onSaveTreeChanges="onSaveTreeChanges"
        @onCancelTree="showNewTree = false"
      ></NewCategory>
    </el-dialog>
    <!-- 新增往来单位弹框 -->
    <DialogSupplierAdd
      ref="supplierAddRef"
      :newData="newData"
      @dialogVisibleClose="onCloseAddSupplier"
      @onAddSubmit="onAddSupplier"
    ></DialogSupplierAdd>
    <!-- 提醒弹框 -->
    <PopupReminder ref="reminderRef" :tipsData="tipsData" @dialogVisibleClose="onNo" @onConfirm="onYes"></PopupReminder>
    <!-- 成功弹框 -->
    <PopupSuccess ref="successRef" :tipsData="tipsData"></PopupSuccess>
    <PopupImportSuccess ref="successImportRef" :tipsData="tipsData"></PopupImportSuccess>
    <!-- 导入 -->
    <DialogImport
      ref="daoru"
      :titles="columnData"
      url="/xghCompany/xghCompany/importExcel"
      :isGoods="true"
      @importData="importData"
      @downloadTemplate="exportExcel"
    ></DialogImport>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { regionData, CodeToText } from 'element-china-area-data'
import CConfiguration from '@/components/c_column/columnConfiguration1'
import NewCategory from '@/components/c_category/NewCategory'
import DialogSupplierAdd from '../../components/dialogSupplierAdd'
import DialogSupplierEdit from '../../components/dialogSupplierEdit'
import PopupReminder from '../../components/popupReminder'
import PopupSuccess from '../../components/popupSuccess'
import PopupImportSuccess from '../../components/popupImportSuccess'
import DialogImport from '@/components/c_Import/index1'
import { postAction, getAction, deleteAction, downPostFile } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
// 导入调用处理权限数据方法
import { handlePermissions, handleOtherPerms, handleIsBaseVersion } from '@/utils/index'
export default {
  name: 'transactionCompanyInfo',
  mixins: [JeecgListMixin],
  components: {
    CConfiguration,
    NewCategory,
    DialogSupplierAdd,
    DialogSupplierEdit,
    PopupReminder,
    PopupSuccess,
    PopupImportSuccess,
    DialogImport,
  },
  computed: {
    ...mapGetters(['name']),
    buttonsPermissions() {
      return handlePermissions('往来单位信息')
    },
  },
  created() {
    // TODO 接口需要增加参数
    if (this.$route.params.data && this.$route.params.data.id) {
      this.queryData.id = this.$route.params.data.id
    }
    this.getData()
  },
  watch: {
    'queryData.status': {
      deep: true,
      handler() {
        this.getTableData()
      },
    },
    filterText(val) {
      this.$refs.tree.filter(val)
    },
    // 路由变化时，更新数据
    $route: {
      immediate: true,
      handler(val) {
        if (val.name === 'baseInfomation-material-transactionCompanyInfo') {
          const data = this.$route.params.data
          if (data && data.id && data.id != this.queryData.id) {
            this.queryData.id = data.id
            this.getTableData()
          }
          this.isBaseVersion = handleIsBaseVersion()
          this.baseText = this.isBaseVersion ? '客户' : '往来单位'
        }
      },
    },
  },
  data() {
    return {
      isBaseVersion: false,
      baseText: '往来单位',
      queryData: {
        status: false,
        queryParam: '',
        xghCompanyTypeId: '',
      },
      // 传递给弹框的数据
      tipsData: {
        tipsState: '',
        tipsWords: '',
        tipsMark: '',
      },
      pagesize: 20, //每页的数据条数
      currentPage: 1, //默认开始页面
      nowLabel: '',
      // 状态按钮数据------------
      importValue: '导入',
      enableValue: '启用',
      enableOptions: [
        {
          value: '启用',
          label: '启用',
        },
        {
          value: '禁用',
          label: '禁用',
        },
      ],
      batchData: [], // 存储多选的数据
      // 树形结构数据------------
      showNewTree: false, //显示树形结构数据新增弹框
      // 传递数据给新增树形结构组件
      newTreeData: {
        parentData: '',
        data: '',
        state: '',
        module: {
          name: '',
        },
      },
      editTreeDataSta: true, //编辑单位类别状态
      companyTypeName: '', //类别查找值
      // 类别数据
      treeData: [],
      defaultProps: {
        children: 'children',
        label: 'label',
      },
      // 表格数据------------
      tableData: {
        records: [],
        total: 0,
      },
      // 列配置数据
      defaultColumnData: [],
      columnData: [
        {
          morenName: '单位名称',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'companyName',
          isRequired: true,
        },
        {
          morenName: '地址',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'address',
        },
        {
          morenName: '联系人',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'companyUserName',
        },
        {
          morenName: '手机',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'companyPhone',
        },
        {
          morenName: '单位编码',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'companyNumber',
        },
        {
          morenName: '拼音码',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'companyPinyinCode',
        },
        {
          morenName: '单位类别',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'xghCompanyTypeId_dictText',
        },
        {
          morenName: '联系电话',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'bankPhone',
        },
        {
          morenName: '税号',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'taxNumber',
        },
        {
          morenName: '开户银行',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'depositBank',
        },
        {
          morenName: '银行账号',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'bankCard',
        },
        {
          morenName: '法定代表',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'representative',
        },
        {
          morenName: '收款期限（天）',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'receivableTime',
        },
        {
          morenName: '付款期限（天）',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'payableTime',
        },
        {
          morenName: '期初应收款',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'beginReceivable',
        },
        {
          morenName: '期初应付款',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'beginPayable',
        },
        {
          morenName: '累计应收款',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'totalReceivable',
        },
        {
          morenName: '累计应付款',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'totalPayable',
        },
        {
          morenName: '应收信用额度',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'receivableQuota',
        },
        {
          morenName: '应付信用额度',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'payableQuota',
        },
        {
          morenName: '预设售价',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'setPrice_dictText',
        },
        {
          morenName: '预设折扣',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'setDiscountPrice_dictText',
        },
      ],
      // 新增数据------------
      newData: {
        companyName: '',
        companyUserName: '',
        // 单位性质
        xghCompanyNatureId: '',
        xghCompanyNature: '',
        companyPhone: '',
        companyPinyinCode: '',
        companyLandline: '',
        xghCompanyTypeId: '', //单位类别
        companyTypeName: '',
        business: '',
        provinceName: '', //省
        provinceCode: '',
        cityName: '', //市
        cityCode: '',
        countyName: '', //区县
        countyCode: '',
        address: '',
        setPrice: '',
        setDiscountPrice: '',
        companyInvoiceStatus: false, //开票信息
        depositBank: '',
        bankName: '',
        bakCard: '',
        taxNumber: '',
        invoiceAddress: '',
        bankPhone: '',
        companyRAndPStatus: false, //应收应付
        beginReceivable: 0,
        beginPayable: 0,
        totalReceivable: 0,
        totalPayable: 0,
        receivableQuota: '',
        payableQuota: '',
        receivableTime: '',
        payableTime: '',
        companyRemark: '',
        companyNumber: '', //单位编码
        companyNationality: '中国',
      },
      ssqOptions: regionData, //省市区选项
      selectedOptions: [], //省市区
      nowTreeId: '', //暂存删除树形节点id
      nowData: {}, //暂存当前行数据
      nowStatus: '', //暂存启用禁用下拉框状态
      nowDataId: '', //暂存删除表数据id
      updateId: '', // 修改列配置时返回的id
      filterText: '',
      url: {
        companyList: '/xghCompany/xghCompany/list',
        api: '往来单位信息',
        exportXlsUrl: '/xghCompany/xghCompany/exportXls',
      },
    }
  },
  mounted() {
    this.selectTitle()
  },
  methods: {
    handleDrop(draggingNode, dropNode, dropType, ev) {
      console.log('tree drop: ', dropNode.label, dropType)
    },
    allowDrop(draggingNode, dropNode, type) {
      if (dropNode.data.label === '二级 3-1') {
        return type !== 'inner'
      } else {
        return true
      }
    },
    allowDrag(draggingNode) {
      return draggingNode.data.label.indexOf('三级 3-2-2') === -1
    },
    // 选中当前行
    onClickRow(row) {
      this.$refs.tableRef.toggleRowSelection(row)
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 初始化查询列配置值
    async selectTitle() {
      let obj = await this.$setColumn.selectColumn(this.url.api)
      if (obj.code === 200) {
        this.updateId = obj.updateId
        this.columnData = obj.columnData
      } else if (obj.code === 500) {
        let id = await this.$setColumn.addColumn(this.url.api, this.$options.data().columnData)
        this.updateId = id
      }
    },
    // 修改列配置后保存修改后的值
    async onSaveColumn(value) {
      this.columnData = value
      let res = await this.$setColumn.editColumn(this.url.api, this.columnData, this.updateId)
      if (res.code == 200) {
        this.$elMessage.success(res.message)
      } else {
        this.$elMessage.error(res.message)
      }
    },
    // 获取数据
    getData() {
      this.getTreeData()
      this.getTableData()
    },
    // 获取类别数据
    getTreeData() {
      getAction('/xghCompanyType/xghCompanyType/childList', {}).then((res) => {
        if (res.code === 200) {
          let list = res.result
          // let result = this.getTreeDataByList(list, '0', '')
          this.treeData = [
            {
              id: '0',
              label: '全部',
              children: this.getTreeDataByList(list, '0', ''),
            },
          ]
        }
      })
    },
    getTreeDataByList(list, parentId, parentName) {
      let data = []
      for (let index = 0; index < list.length; index++) {
        const element = list[index]
        if (element.pid == parentId) {
          data.push({
            ...element,
            id: element.id,
            label: element.companyTypeName,
            parentId,
            parentName,
            children: this.getTreeDataByList(list, element.id, element.companyTypeName),
          })
        }
      }
      return data
    },
    // 获取表格数据
    getTableData(page) {
      let data = {
        ...this.queryData,
        pageSize: this.pagesize,
        pageNo: page || 1, //只有切换页码时这个值会变化，其他触发都是第一页
      }
      data.status = data.status ? '1' : '0'
      getAction(this.url.companyList, data).then((res) => {
        if (res.code === 200) {
          let result = res.result
          result.records.forEach((item) => {
            item.status = item.status == '0' ? true : false
          })
          this.tableData = result
        }
      })
    },
    // 提醒弹框确认后操作
    onYes(mark) {
      if (mark == 'onBatchDelete') {
        var idsDel = []
        this.batchData.forEach((item) => {
          idsDel.push(item.id)
        })
        deleteAction('/xghCompany/xghCompany/deleteBatch', {
          ids: idsDel.toString(),
        }).then((res) => {
          if (res.code === 200) {
            this.$elMessage.success(res.message)
            let arr = this.$lcStorage.get('wldwHistoricalRecords')
            if (arr && arr.length > 0) {
              idsDel.forEach((item) => {
                arr.forEach((val, key) => {
                  if (item === val.id) {
                    arr.splice(key, 1)
                    return
                  }
                })
              })
            }
            this.$lcStorage.set('wldwHistoricalRecords', arr)
            this.getTableData()
          } else {
            this.$elMessage.error(res.message)
          }
        })
      } else if (mark == 'onDeleteRow') {
        let data = {
          id: this.nowDataId,
        }
        deleteAction('/xghCompany/xghCompany/delete', data).then((res) => {
          if (res.code === 200) {
            this.$elMessage.success(res.message)
            let arr = this.$lcStorage.get('wldwHistoricalRecords')
            if (arr && arr.length > 0) {
              arr.forEach((item, index) => {
                if (item.id === this.nowDataId) {
                  arr.splice(index, 1)
                }
              })
              this.$lcStorage.set('wldwHistoricalRecords', arr)
            }

            this.getTableData()
          } else {
            this.$elMessage.error(res.message)
          }
        })
      } else if (mark == 'onBatchChangeStatus') {
        let ids = []
        this.batchData.forEach((item) => {
          ids.push(item.id)
        })
        postAction('/xghCompany/xghCompany/updateCompanyStatus', {
          id: ids.toString(),
          status: this.nowStatus == '启用' ? '0' : '1',
        }).then((res) => {
          if (res.code === 200) {
            this.$elMessage.success(res.result)
            this.getTableData()
          } else {
            this.$elMessage.error(res.message)
          }
        })
      } else if (mark == 'onChangeStatus') {
        postAction('/xghCompany/xghCompany/updateCompanyStatus', {
          id: this.nowData.id,
          status: this.nowData.status ? '0' : '1',
        }).then((res) => {
          if (res.code === 200) {
            this.$elMessage.success(res.result)
            if (!this.queryData.status) {
              this.getTableData()
            }
          } else {
            this.$elMessage.error(res.message)
            this.nowData.status = !this.nowData.status
          }
        })
      } else if (mark == 'onDeleteTree') {
        let data = {
          id: this.nowTreeId,
        }
        deleteAction('/xghCompanyType/xghCompanyType/delete', data).then((res) => {
          if (res.code === 200) {
            this.getTreeData()
            // this.editTreeDataSta = true
          } else {
            this.$elMessage({
              showClose: true,
              message: res.message,
              type: 'error',
              iconClass: 'el-icon-warning-outline',
              duration: 3000,
            })
          }
        })
      }
    },
    // 提醒弹框确认后操作
    onNo(mark) {
      console.log('onNo')
      if (mark == 'onChangeStatus') {
        this.tableData.records.forEach((item) => {
          if (item.id == this.nowData.id) {
            item.status = !item.status
          }
        })
      }
    },
    // 新增
    handleShortcutKeyAdd() {
      this.onShowAdd()
    },
    // 打开新增数据弹框
    onShowAdd() {
      if (!this.buttonsPermissions.XinZeng) {
        this.$elMessage.warning('未拥有新增权限！')
        return
      }
      this.$refs.supplierAddRef.dialogVisible = true
      this.$refs.supplierAddRef.reloadData()
    },
    // 批量启用禁用数据
    onBatchChangeStatus(val) {
      if (this.batchData && this.batchData.length) {
        this.nowStatus = val
        this.tipsData.tipsWords = '是否确认批量' + val + '?'
        this.tipsData.tipsMark = 'onBatchChangeStatus'
        this.$refs.reminderRef.dialogVisible = true
      } else {
        this.$elMessage({
          showClose: true,
          message: '请先选择需要' + val + '的数据！',
          type: 'error',
          iconClass: 'el-icon-warning-outline',
          duration: 3000,
        })
      }
      this.enableValue = '启用'
    },
    // 批量删除数据
    onBatchDelete() {
      if (this.batchData && this.batchData.length) {
        this.tipsData.tipsState = 'delete'
        this.tipsData.tipsWords = '是否确认批量删除?'
        this.tipsData.tipsMark = 'onBatchDelete'
        this.$refs.reminderRef.dialogVisible = true
      } else {
        this.$elMessage({
          showClose: true,
          message: '请先选择需要删除的数据！',
          type: 'error',
          iconClass: 'el-icon-warning-outline',
          duration: 3000,
        })
      }
    },
    // 搜索
    onQuery() {
      this.getTableData()
    },
    // 刷新
    onRefresh() {
      Object.assign(this.$data, this.$options.data())
      this.selectTitle()
      this.getTreeData()
    },
    // 触发列配置弹框
    onShowColumn() {
      this.defaultColumnData = this.$options.data().columnData
      this.$refs.setColumnRef.dialogVisible = true
    },
    // 搜索树形结构数据
    onSelectTree() {
      this.getTreeData()
    },
    // 触发树形当前节点
    handleNodeClick(data) {
      if (this.editTreeDataSta) {
        //非编辑状态
        if (this.queryData.xghCompanyTypeId != data.id) {
          this.queryData.xghCompanyTypeId = data.id == 0 ? undefined : data.id
          this.newData.xghCompanyTypeId = data.id == 0 ? '' : data.id
          this.getTableData()
        }
      } else {
        this.nowLabel = data.id
      }
    },
    handleImgClick(row, type) {
      console.log(row, type)
      // 销售出库单
      if (type == 'xsckd') {
        this.$router.push({
          // path: '/saleManage/salesBill/billSalesDelivery',
          name: 'saleManage-salesBill-billSalesDelivery',
          params: {
            xghCompanyId: row.id,
          },
        })
      }
      // 采购入库单
      else if (type == 'cgrkd') {
        this.$router.push({
          // path: '/purchaseManage/purchaseBill/billPurchaseWarehousing',
          name: 'purchaseManage-purchaseBill-billPurchaseWarehousing',
          params: {
            xghCompanyId: row.id,
          },
        })
      }
      // 往来对账单
      else if (type == 'wldzd') {
        this.$router.push({
          // path: '/reportStatistics/paymentReport/arAndapReconciliation',
          name: 'reportStatistics-paymentReport-arAndapReconciliation',
          params: {
            xghCompanyId: row.id,
          },
        })
      }
      // 付款单
      else if (type == 'fkd') {
        this.$router.push({
          // path: '/paymentManage/paymentBill/billPaymentSettlement',
          name: 'paymentManage-paymentBill-billPaymentSettlement',
          params: {
            xghCompanyId: row.id,
          },
        })
      }
      // 收款单
      else if (type == 'skd') {
        this.$router.push({
          // path: '/paymentManage/paymentBill/billCollectionSettlement',
          name: 'paymentManage-paymentBill-billCollectionSettlement',
          params: {
            xghCompanyId: row.id,
          },
        })
      }
    },
    // 获取当前节点祖先节点id
    // findTopAncestorId(data) {
    //   // 使用 el-tree 的 getNode 方法获取节点对象
    //   let currentNode = this.$refs.tree.getNode(data)
    //   while (currentNode.level > 1) {
    //     currentNode = currentNode.parent
    //   }
    //   return currentNode.data.id // 返回顶级祖先节点的 ID
    // },
    // 触发新增树形节点按钮
    onAddTree(data) {
      this.newTreeData = {
        data: data,
        state: 'add',
        module: {
          name: 'companyTypeName', //类别名称字段
          code: 'companyCode', //类别编码字段
          pyCode: 'companyPinyinCode', //类别拼音码字段
          indexCode: 'companyIndexCode', //类别排序码字段
        },
        getTreeUrl: '/xghCompanyType/xghCompanyType/childList', //获取类别接口
        deleteTreeUrl: '/xghCompanyType/xghCompanyType/delete', //删除类别接口
        addTreeUrl: '/xghCompanyType/xghCompanyType/add', //新增类别接口
        editTreeUrl: '/xghCompanyType/xghCompanyType/edit', //修改类别接口
      }
      this.showNewTree = true
    },
    // 触发修改树形节点按钮
    onEditTree(node, data) {
      this.newTreeData = {
        data: data,
        state: 'edit',
        module: {
          name: 'companyTypeName', //类别名称字段
          code: 'companyCode', //类别编码字段
          pyCode: 'companyPinyinCode', //类别拼音码字段
          indexCode: 'companyIndexCode', //类别排序码字段
        },
        getTreeUrl: '/xghCompanyType/xghCompanyType/childList', //获取类别接口
        deleteTreeUrl: '/xghCompanyType/xghCompanyType/delete', //删除类别接口
        addTreeUrl: '/xghCompanyType/xghCompanyType/add', //新增类别接口
        editTreeUrl: '/xghCompanyType/xghCompanyType/edit', //修改类别接口
      }
      this.showNewTree = true
    },
    // 类别信息新增/修改后数据获取
    onSaveTreeChanges() {
      this.getTreeData()
      this.showNewTree = false
      // this.editTreeDataSta = true
    },
    // 类别信息取消按钮触发
    onCancelTree() {
      this.showNewTree = false
    },
    // 触发删除树形节点按钮
    onDeleteTree(data) {
      if (data.children && data.children.length) {
        this.$elMessage({
          showClose: true,
          message: '类别下级有分类，不允许删除！',
          type: 'error',
          iconClass: 'el-icon-warning-outline',
          duration: 3000,
        })
      } else {
        this.tipsData.tipsState = 'delete'
        this.tipsData.tipsWords = '是否确认删除?'
        this.tipsData.tipsMark = 'onDeleteTree'
        this.$refs.reminderRef.dialogVisible = true
        this.nowTreeId = data.id
      }
    },
    // 触发表格修改按钮
    onEditRow(val) {
      val.companyInvoiceStatus = val.companyInvoiceStatus == 0 ? true : false
      val.companyRAndPStatus = val.companyRAndPStatus == 0 ? true : false
      this.newData = Object.assign({}, this.newData, val)
      this.$refs.supplierAddRef.dialogVisible = true
      this.$refs.supplierAddRef.reloadData()
    },
    // 删除当前行
    onDeleteRow(row) {
      this.tipsData.tipsState = 'delete'
      this.tipsData.tipsWords = '是否确认删除?'
      this.tipsData.tipsMark = 'onDeleteRow'
      this.$refs.reminderRef.dialogVisible = true
      this.nowDataId = row.id
    },
    // 启用或禁用往来单位
    onChangeStatus(val) {
      this.nowData = val
      this.tipsData.tipsWords = '是否确认' + (val.status ? '启用' : '禁用') + '?'
      this.tipsData.tipsMark = 'onChangeStatus'
      this.$refs.reminderRef.dialogVisible = true
    },
    // 获取新增客户数据
    onAddSupplier() {
      this.newData = this.$options.data().newData
    },
    // 获取修改客户数据
    onEditSupplier() {
      this.getData()
      this.newData = this.$options.data().newData
    },
    // 关闭新增往来单位时清空
    onCloseAddSupplier() {
      this.getData()
      this.newData = this.$options.data().newData
    },
    // 关闭修改往来单位时清空
    onCloseEditSupplier() {
      this.getData()
      this.newData = this.$options.data().newData
    },
    // 获取每页几条数据
    handleSizeChange(val) {
      this.pagesize = val
      this.getTableData()
    },
    // 获取当前第几页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getTableData(val)
    },
    // 触发表格多选按钮
    handleSelectionChange(val) {
      this.batchData = val
    },
    // 导入数据
    importExcel() {
      this.$refs.daoru.dialogVisible = true
    },
    importData(res) {
      this.tipsData.tipsWords = res.message
      this.$refs.successImportRef.dialogVisible = true
      this.getData()
    },
    // 导出数据
    exportExcel() {
      let list = []
      // if (this.batchData && this.batchData.length > 0) {
      //   for (let index = 0; index < this.batchData.length; index++) {
      //     const element = this.batchData[index]
      //     list.push(element.id)
      //   }
      // } else {
      //   this.$elMessage.warning('请选择想要导出的数据！')
      //   return
      // }
      let queryParam = {
        fileName: this.baseText,
        selections: list.join(','),
      }
      this.handleExportXlsByStaff(this.baseText, queryParam)
    },
  },
}
</script>

<style lang="scss" scoped>
.option-icon {
  width: 17px;
  height: 17px;
  margin: 5px 6px;
  cursor: pointer;
  flex-shrink: 0;
}
.basic_info {
  width: 100%;
  height: calc(100vh - 1.875117rem);
  background: #f0f2f5;
  box-sizing: border-box;
  padding: 0 0.168761rem 0.168761rem;
  display: flex;
  flex-direction: column;
}
.info_operation_btn {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  .el-button {
    // @include flex-center;
    width: 70px;
    height: 30px;
    text-align: center;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    border-radius: 0.1rem;
    border: none;
    margin-right: 0.112507rem;
    padding: 0;
  }
  .el-button--default {
    color: #666;
  }
  .btn_left {
    width: 50%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    ::v-deep .el-checkbox__label {
      font-size: 12px;
      padding-left: 0.1rem;
    }
    ::v-deep .el-select {
      width: 70px;
      height: 30px;
      box-sizing: border-box;
      margin-right: 0.112507rem;
      .el-input {
        .el-input__inner {
          height: 30px;
          border: none;
          font-size: 12px;
        }
        .el-input__suffix {
          height: 30px;
          display: flex;
          align-items: center;
        }
      }
    }
  }
  .btn_right {
    width: 50%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .el-input {
      width: 4.725295rem;
      height: 30px;
      margin-right: 0.112507rem;
      ::v-deep .el-input__inner {
        height: 30px;
        border: none;
        box-sizing: border-box;
        padding: 0 0.15rem;
        background: #fff;
        font-size: 12px;
        color: #666;
        &::placeholder {
          font-size: 12px;
          color: #c1c1c1;
        }
      }
    }
    .el-button {
      width: 70px;
      margin-left: 0;
    }
    .set_up {
      font-size: 23px;
      color: rgb(153, 153, 153);
    }
  }
}
.info_content_div {
  width: 100%;
  height: calc(100% - 1rem);
  background: #fff;
  box-sizing: border-box;
  padding: 0.168761rem;
  display: flex;
  .div_tree {
    width: 2.812676rem;
    height: calc(100% - 1rem);
    box-sizing: border-box;
    padding: 0.131258rem 0;
    border: 0.018751rem solid #e3e3e3;
    transition: all 0.3s;
    .tree_div1 {
      width: 100%;
      height: 30px;
      box-sizing: border-box;
      padding: 0 10px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      p {
        color: #666666;
        font-size: 12px;
        margin: 0;
        &:last-child {
          color: #1b93f9;
        }
      }
      .el-button {
        width: 70px;
        height: 0.38rem;
        text-align: center;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        border-radius: 0;
        border: none;
      }
    }
    .tree_input {
      width: 100%;
      // height: 30px;
      height: 30px;
      margin-top: 0.131258rem;
      box-sizing: border-box;
      padding: 0 0.168761rem;
      p {
        width: 100%;
        // height: 30px;
        height: 30px;
        margin: 0;
        box-sizing: border-box;
        border: 1px solid #dddddd;
        display: flex;
        align-items: center;
        position: relative;
        input {
          width: 100%;
          box-sizing: border-box;
          padding: 0 5px;
          height: 28px;
          border: none;
          font-size: 12px;
          &:focus {
            outline: none;
          }
        }
        span {
          position: absolute;
          right: 0;
          display: flex;
          align-items: center;
          justify-content: center;
          width: 0.55rem;
          height: 28px;
          background: #fff;
          .el-icon-search {
            font-size: 0.25rem;
            color: rgb(211, 211, 211);
          }
        }
      }
    }
    .tree_structure {
      width: 100%;
      height: calc(100% - 0.337521rem - 0.131258rem - 0.131258rem - 0.55rem);
      box-sizing: border-box;
      padding: 0 0.168761rem;
      margin-top: 0.131258rem;
      overflow: auto;
      ::v-deep .el-tree {
        width: 100%;
        .tree_node {
          width: 100%;
          display: flex;
          align-items: center;
          justify-content: space-between;
          span {
            font-size: 12px;
          }
          .tree_label {
            width: 7em;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          .show_nodex {
            display: flex;
            align-items: center;
            font-size: 0.25rem;
            i {
              margin-right: 0.15rem;
              font-weight: 600;
            }
            .el-icon-circle-plus-outline {
              color: #1993fb;
            }
            .el-icon-edit-outline {
              color: #1993fb;
            }
            .el-icon-delete {
              color: #ff2626;
            }
          }
        }
        .el-tree-node__children {
          .el-tree-node__label {
            color: #666;
            font-weight: normal;
          }
        }
        .el-tree-node__label {
          font-size: 12px;
          font-weight: 600;
        }
        .is-current {
          .el-tree-node__content {
            background-color: #e6f7ff;
          }
        }
        .el-tree-node__content > .el-tree-node__expand-icon {
          padding-left: 0;
        }
      }
    }
  }
  .new_div_tree_width {
    width: 4.125258rem;
  }
  .div_table {
    width: calc(100% - 3rem);
    height: 100%;
    margin-left: 0.187512rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.3s;
    .table_content {
      height: calc(100% - 1.687605rem);
      ::v-deep .el-table {
        border: 1px solid #e3e3e3;
        border-bottom: none;
        box-sizing: border-box;
        th,
        td {
          padding: 0;
          color: #666;
          box-sizing: border-box;
          border-right: 1px solid #e3e3e3;
          .cell {
            min-height: 30px;
            display: flex;
            align-items: center;
            font-size: 12px;
          }
          &:first-child {
            .cell {
              justify-content: center;
              padding: 0;
            }
          }
          &:nth-child(2) {
            .cell {
              justify-content: center;
            }
          }
          &:last-child {
            .cell {
              justify-content: center;
            }
          }
        }
        th {
          .cell {
            background: #ededed;
            justify-content: center;
          }
        }
        .el-checkbox {
          .is-indeterminate {
            .el-checkbox__inner {
              color: #1b93f9;
              background-color: #1b93f9;
              border-color: #1b93f9;
            }
          }
        }
        .el-icon-edit-outline {
          font-size: 20px;
          color: #1b93f9;
          margin: 0 5px;
        }
        .el-icon-delete {
          font-size: 20px;
          color: #ff2626;
          margin: 0 5px;
        }
        .el-table__body tr:hover > td {
          background: #e3f6ff;
        }
        .el-table__footer-wrapper {
          td {
            background: #f4f4f4;
            border: none;
          }
        }
        //滚动条的宽度
        ::-webkit-scrollbar {
          width: 8px;
          height: 10px;
          background-color: #e5e5e5;
        }
        //滚动条的滑块
        ::-webkit-scrollbar-thumb {
          background-color: #c9c9c9;
        }
      }
    }
    .total_record {
      width: 100%;
      height: 30px;
      box-sizing: border-box;
      padding: 0 0.25rem;
      border: 1px solid #e3e3e3;
      border-top: none;
      background: #f4f4f4;
      display: flex;
      p {
        margin: 0;
        line-height: 30px;
        padding-right: 0.25rem;
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #666666;
      }
    }
    .table_pagination {
      width: 100%;
      height: 50px;
      box-sizing: border-box;
      padding: 0.168761rem 0;
      display: flex;
      .pagination_div {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        ::v-deep .el-pagination {
          padding: 0;
          height: 30px;
          .el-pagination__sizes {
            margin: 0;
            .el-input {
              margin-right: 0;
            }
          }
        }
      }
    }
  }
  .new_div_table_width {
    width: calc(100% - 4.31277rem);
  }
}
.disabled_button {
  background: #cbced3 !important;
  color: #666 !important;
}
</style>
